<template>
	<view>
		<uni-nav-bar @clickLeft='goback' color="#fff" backgroundColor='' left-icon="back" :border='false'
			statusBar="true"></uni-nav-bar>
		<view class="tit">
			<view class="">
				<view class="">
					欢迎使用
				</view>
				<image src="/static/logo.png" mode=""></image>
			</view>
			<view class="rigimg">
				<image src="../../static/log2.png" mode=""></image>
			</view>
		</view>

		<view class="content">
			<view class="inputs">
				<input v-model="params.phone" type="number" maxlength="11" placeholder-class="input"
					placeholder="请输入手机号" />
			</view>
			<view class="inputs">
				<input v-model="params.code" type="number" placeholder-class="input" placeholder="请输入验证码" />
				<view class="" @click="getPhonecode">
					{{codeBtn.codeText}}
				</view>
			</view>

			<view class="btns">
				<view class="btn" @click="handleLogin">
					登录
				</view>
			</view>
			<view class="tipsre">
				<view class="abssjs" v-if="isshow">
					请先阅读并同意 伊可库用户协议 及 隐私政策
				</view>
				<view class="xy" @click="handlexy">
					<image v-if="isyes" src="../../static/yuana.png" mode=""></image>
					<image v-else src="../../static/yuan.png" mode=""></image>
					<view class="">
						我已阅读并同意<span @click.stop="pagego(1)">伊可库用户协议</span>及<span @click.stop="pagego(2)">隐私政策</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		codeLogin,
		getCode
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				isshow: false,
				isyes: false,
				params: {
					openid_code: '',
					inviteId:uni.getStorageSync('userinviteId')?uni.getStorageSync('userinviteId'):'',
					phone: '',
					code: ''
				},
				//验证码按钮
				codeBtn: {
					codeTime: 60,
					codeText: "获取验证码",
					codeStatus: true
				}
			};
		},
		methods: {
			pagego(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/mypage/contactus/useragreement'
					})
				} else {
					uni.navigateTo({
						url: '/mypage/contactus/agreement'
					})
				}
			},
			handleLogin() {
				let that = this
				if (!that.isyes) {
					that.isshow = true
					return
				}

				if (that.params.phone == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号！'
					})
					return
				}
				if (that.params.code == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入验证码！'
					})
					return
				}
				uni.showLoading({
					title: '登录中...'
				})
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						that.params.openid_code = loginRes.code
						codeLogin(that.params).then(res => {
							if (res.code == 200) {
								uni.setStorageSync('userToken', res.data.token)
								uni.hideLoading()
								if (uni.getStorageSync('isHttp')) {
									uni.reLaunch({
										url: '/pages/index/index'
									})
								} else {
									uni.navigateBack({
										delta: 2
									});
								}
								uni.removeStorageSync('isHttp')
							}
						})


					}
				});

			},
			goback() {
				uni.navigateBack()
			},
			handlexy() {
				this.isyes = !this.isyes
				if (this.isyes) {
					this.isshow = false
				}
			},
			getPhonecode() {
				let reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
				if (this.params.phone == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号'
					})
					return
				}
				if (!reg_tel.test(this.params.phone)) {
					uni.showToast({
						icon: 'none',
						title: '手机号格式错误'
					})
					return
				}
				if (this.codeBtn.codeStatus) {
					getCode({
						phone: this.params.phone
					}).then(res => {
						console.log(res);
						if(res.code = 200){
							this.codeBtn.codeStatus = false
							let timerId = setInterval(() => {
								let codetime = this.codeBtn.codeTime
								codetime--
								this.codeBtn.codeTime = codetime
								this.codeBtn.codeText = codetime + "s"
								if (codetime < 1) {
									clearInterval(timerId)
									this.codeBtn.codeText = "重新获取"
									this.codeBtn.codeTime = 60
									this.codeBtn.codeStatus = true
									this.params.code = ''
								}
							}, 1000)
						}
					})
					
				}

			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #29A85C;
		height: 100vh;
		overflow: hidden;
	}

	.tit {
		margin: 42rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 48rpx;
		color: #000000;
		display: flex;
		justify-content: space-between;

		image {
			margin-top: 18rpx;
			width: 284rpx;
			height: 90rpx;
		}

		.rigimg {
			width: 304rpx;
			height: 503rpx;

			image {
				width: 304rpx;
				height: 503rpx;
			}
		}
	}

	.content {
		position: fixed;
		bottom: 0%;
		width: 750rpx;
		height: 1038rpx;
		background: #FFFFFF;
		border-radius: 80rpx 80rpx 0rpx 0rpx;
		padding: 104rpx 40rpx;
		box-sizing: border-box;

		.inputs {
			width: 670rpx;
			height: 100rpx;
			background: #FFFFFF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 2rpx solid #000000;
			padding: 28rpx 30rpx;
			box-sizing: border-box;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			margin-bottom: 40rpx;

			input {
				flex: 1;
			}

			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.input {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #D9D5D4;
		}

		.btns {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			line-height: 100rpx;
			text-align: center;

			.btn {
				width: 670rpx;
				height: 100rpx;
				background: #000000;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				margin-bottom: 40rpx;
				color: #FFFFFF;
			}
		}

		.tipsre {
			width: 100%;
			position: fixed;
			bottom: 60rpx;
			width: 580rpx;
			left: 50%;
			transform: translateX(-50%);

			.abssjs {
				width: 580rpx;
				background: rgba(0, 0, 0, 0.8);
				border-radius: 10rpx;
				position: relative;
				padding: 10rpx 30rpx;
				box-sizing: border-box;
				font-size: 26rpx;
				color: #FFFFFF;
				margin: 15rpx auto;
			}

			.abssjs:after {
				content: "";
				border: 12rpx solid rgba(0, 0, 0, 0.8);
				border-top-color: rgba(0, 0, 0, 0.8);
				border-right-color: transparent;
				border-bottom-color: transparent;
				border-left-color: transparent;
				width: 0px;
				height: 0px;
				position: absolute;
				left: 35rpx;
				font-size: 26rpx;
				bottom: -24rpx;
			}

			.xy {
				display: flex;
				align-items: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #D1D1D6;
				text-align: center;
				width: 520rpx;
				margin: 0 auto;

				span {
					color: #000;
					margin: 0 6rpx;
				}

				image {
					width: 30rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}
			}
		}
	}
</style>